package com.news.wemedia.controller.v1.wemedia;

import com.news.model.common.dtos.ResponseResult;
import com.news.model.wemedia.dtos.WmChannelDto;
import com.news.model.wemedia.pojos.WmChannel;
import com.news.wemedia.service.WmChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/channel")
public class WmchannelController {

    @Autowired
    private WmChannelService wmChannelService;

    /**
     * 查询频道
     * @return
     */
    @GetMapping("/channels")
    @Cacheable(value = "channels",key = "")
    public ResponseResult findAll(){
        return wmChannelService.findAll();
    }

    /**
     * 频道名称模糊分页查询
     * @param wmChannelDto
     * @return
     */
    @PostMapping("list")
    public ResponseResult getList(@RequestBody WmChannelDto wmChannelDto){
        return wmChannelService.listPage(wmChannelDto);
    }

    /**
     * 新增频道
     * @param wmChannel
     * @return
     */
    @PostMapping("save")
    @CacheEvict(value = "channels",key = "",allEntries = true)
    public ResponseResult save(@RequestBody WmChannel wmChannel){
        return wmChannelService.saveOne(wmChannel);
    }

    /**
     * 删除频道
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    @CacheEvict(value = "channels",key = "",allEntries = true)
    public ResponseResult del(@PathVariable Integer id){
        return wmChannelService.delOne(id);
    }

    /**
     * 修改频道
     * @param wmChannel
     * @return
     */
    @PostMapping("/update")
    @CacheEvict(value = "channels",key = "",allEntries = true)
    public ResponseResult update(@RequestBody WmChannel wmChannel){
        return wmChannelService.updateOne(wmChannel);
    }
}
